package com.niit.demo04;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class imageView extends AppCompatActivity {
    Button changeLast,changeNext;
    ImageView imgDisplay;
    int [] image = {R.drawable.img01,R.drawable.img02,R.drawable.img03,R.drawable.img04,R.drawable.img05};
    int counts = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_view);
        changeLast = findViewById(R.id.last);
        changeNext = findViewById(R.id.next);
        imgDisplay = findViewById(R.id.img);

        imgDisplay.setImageResource(image[0]);

        changeNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (counts >=4){
                    counts = 0;
                }
                imgDisplay.setImageResource(image[++counts]);
            }
        });

        changeLast.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (counts <=0){
                    counts = 4;
                }
                imgDisplay.setImageResource(image[--counts]);
            }
        });
    }
}
